/*
 * File     : SetsLastError.java
 * Created  : 18 Dec 2011
 *
 * Copyright © 2011 Matthew Wilson (mj. {my-surname} .uk {at} gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.dni.library;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.googlecode.dni.DirectNativeInterface;

/**
 * <p>
 *  Annotates a function in a library to indicate that the function sets the
 *  platform-specific 'last error' value.
 * </p>
 * <p>
 *  The 'last error' mechanism is <code>GetLastError</code> under Windows, and
 *  <code>errno</code> under POSIX.
 *  The value can be read by calling
 *  {@link DirectNativeInterface#getLastError()} on the same thread.
 *  There is a small overhead of adding this check into the native call.
 * </p>
 * <p>
 *  (Note that a mandated exception was not chosen as the design since some
 *  functions return values that can be processed <em>and</em> set an error
 *  code.
 *  Furthermore, it is not possible to make the same system call to read the
 *  value since JNI and other Java internals may well corrupt the value between
 *  the two calls.)
 * </p>
 *
 * @author Matthew Wilson
 */
@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.METHOD )
public @interface SetsLastError
{

    /**
     * Whether an exception will be thrown when the 'last error' is non-zero.
     *
     * @return <code>true</code> iff an exception will be thrown
     *
     * @see SystemException
     */
    boolean throwOnNonZero() default true;

}
